
		<div class="easyui-layout" data-options="fit:true">
			<table id="productSalesTable" class="easyui-datagrid" style="height:100%;">
				<thead frozen="true">
					<tr>
						<th data-options="field:'date',width:80,align:'center'">日期</th>
					</tr>
				</thead>
				<thead>
						<tr>
						<th data-options="field:'producttotalprice',width:50,align:'center',rowspan:2" formatter='formatProductTotalPrice'>产品<br>金额合计</th>
							<th data-options="field:'sum',width:80,align:'center',rowspan:2" formatter='formatSum'>总计</th>
							<th data-options="field:'singlelc',width:80,align:'center'" >单疗程</th>
							<th data-options="field:'normlc',width:80,align:'center',colspan:2" >标准疗程</th>
							<th data-options="field:'uplc',width:80,align:'center',colspan:2" >转疗程</th>
							<%if(!isEmpty(products)){%>
								<%for(product in products){%>
									<th data-options="field:'${product.bh! }',width:80,align:'center',colspan:2">${product.name! }</th>
								<%}%>
							<%}%>
							
						</tr>
						<tr>
							<!-- <th data-options="field:'singlelc_unitprice',width:50,align:'center'" >单价(元)</th> -->
							<th data-options="field:'singlelc_totalprice',width:50,align:'center'" >金额(元)</th>
							<th data-options="field:'normlc_lcnum',width:50,align:'center'" >疗程数</th>
							<!-- <th data-options="field:'normlc_unitprice',width:50,align:'center'" >单价(元)</th> -->
							<th data-options="field:'normlc_totalprice',width:50,align:'center'" >金额(元)</th>
							<th data-options="field:'uplc_lcnum',width:50,align:'center'" >疗程数</th>
							<th data-options="field:'uplc_totalprice',width:50,align:'center'" >金额(元)</th>
							<%if(!isEmpty(products)){%>
								<%for(product in products){%>
									<th data-options="field:'${product.bh! }_num',width:80,align:'center'">数量</th>
									<th data-options="field:'${product.bh! }_price',width:80,align:'center'">金额</th>
								<%}%>
							<%}%>
							
						</tr>
					</thead>
			</table>
			<div id="productSales_tb" >
				日期：
				<input id="productSales_startTime" value='${startTime! }' class="easyui-datebox theme-textbox-radius"  data-options="editable: false"/>~
				<input id="productSales_endTime" value='${date(),dateFormat="yyyy-MM-dd"}' class="easyui-datebox theme-textbox-radius" data-options="editable: false"/>
			</div>
		</div>
		<script type="text/javascript">
			$(document).ready(function () {
				//加载数据表格
				loadProductSalesTable();
				$('#productSales_startTime').datebox({
					onSelect: function(date){
						loadProductSalesTable();
					}
				});
				$('#productSales_endTime').datebox({
					onSelect: function(date){
						loadProductSalesTable();
					}
				});
			});
			
			function  loadProductSalesTable() {	
				var startTime = $("#productSales_startTime").val();
				var endTime = $("#productSales_endTime").val();
				$('#productSalesTable').datagrid({
					cls: "theme-datagrid",
					toolbar: '#productSales_tb',
					singleSelect: true,
					rownumbers: true, //显示序号
					url: "${cxt!}/customerInfoStatistic/lookCustomerProductSales",
					queryParams: {
						'customerIds': '${customerIds! }',
						'startTime': startTime,
						'endTime': endTime
					},
				    method: 'post',
					collapsible: true,
					onLoadSuccess:function(){
						var rows = $('#productSalesTable').datagrid('getRows');
						if(rows.length > 0){
							$('#productSalesTable').datagrid('insertRow', {
								index:0,
								row:{
									date: '合计',
									singlelc_totalprice: compute('singlelc_totalprice'),
									normlc_lcnum: compute('normlc_lcnum'),
									normlc_totalprice: compute('normlc_totalprice'),
									uplc_lcnum: compute('uplc_lcnum'),
									uplc_totalprice: compute('uplc_totalprice'),
									producttotalprice:compute('producttotalprice'),
									<%
										if(!isEmpty(products)){
											for(product in products){
												print(product.bh + '_num : compute(\'' + product.bh + '_num\'),');
												print(product.bh + '_price : compute(\'' + product.bh + '_price\'),');
											}
										}
									%>
									sum: compute('sum')
								}
				             });
						}
					},
				})
			}
			
			//指定列求和
	        function compute(colName) {
	             var rows = $('#productSalesTable').datagrid('getRows');
	             var total = 0;
	             for (var i = 0; i < rows.length; i++) {
	            	 if(typeof(rows[i][colName]) != 'undefined'){
	            		 total += parseFloat(rows[i][colName]);
	            	 }
	             }
	             if(total > 0){
	            	 return total;
	             }else{
	            	 return '';
	             }
	         }
			
			//减重+产品求和
			function formatSum(value,row){
				var total = 0;
				if(typeof(row.singlelc_totalprice) != 'undefined' && row.singlelc_totalprice != ''){
           		 	total += parseFloat(row.singlelc_totalprice);
           	 	}
				if(typeof(row.normlc_totalprice) != 'undefined' && row.normlc_totalprice != ''){
           		 	total += parseFloat(row.normlc_totalprice);
           	 	}
				if(typeof(row.uplc_totalprice) != 'undefined' && row.uplc_totalprice != ''){
           		 	total += parseFloat(row.uplc_totalprice);
           	 	}
				if(typeof(row.producttotalprice) != 'undefined' && row.producttotalprice != ''){
           		 	total += parseFloat(row.producttotalprice);
           	 	}
				if(total > 0){
	            	return total;
	            }else{
	            	return '';
	            }
			}
			
			//格式化产品求和
			function formatProductTotalPrice(value,row){
				var sum = row.producttotalprice;
				if(sum == 0){
					return '';
				}else{
					return sum;
				}
			}
		</script>
